<template>
  <div class="app-container expert">
    <el-card class="card-form">
      <div class="expert-title">专家评审任务</div>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="任务名称" prop="taskName">
          <el-input
            v-model="queryParams.taskName"
            placeholder="请输入"
            clearable
            size="small"
            style="width: 252px"
          />
        </el-form-item>
        <el-form-item label="任务创建时间">
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="checkTime"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="任务节点" prop="extractNode">
          <el-select
            v-model="queryParams.extractNode"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 252px"
          >
            <el-option
              v-for="dict in nodeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="任务状态" prop="domain">
          <el-select
            v-model="queryParams.status"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 252px"
          >
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" size="small" @click="handleQuery"
            >查询</el-button
          >
          <el-button size="small" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="card-table">
      <status-bar :status="processingStatusMap" @change="changeProcessingStatus"></status-bar>
      <el-table v-loading="loading" :data="reviewTasktList" border>
        <el-table-column label="序号" align="center" type="index" width="65" />
        <el-table-column
          label="任务名称"
          align="center"
          prop="taskName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="任务创建时间"
          align="center"
          prop="createTime"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="任务节点" align="center" prop="extractNode">
          <template slot-scope="scope">
            {{
              scope.row.extractNode == 9 || scope.row.extractNode == 10
                ? "接受任务"
                : scope.row.extractNode == 11 ||
                  scope.row.extractNode == 12 ||
                  scope.row.extractNode == "在线预审"
                ? "在线预审"
                : scope.row.extractNode == 16 ||
                  scope.row.extractNode == 17
                ? "现场论证"
                : "--"
            }}
          </template>
        </el-table-column>
        <el-table-column
          label="任务状态"
          align="center"
          width="170px"
          prop="status"
        >
          <template slot-scope="scope">
            <span class="icon-state" :class="scope.row.processingStatus|getIconClass"
              ><span></span
            ></span>
            <span>
              {{
                scope.row.processingStatus
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <!-- {{scope.row}} -->
            <!-- 0 处理  1 申请取消 2 查看详情/查看-->
            <el-button
              size="mini"
              v-if="scope.row.status == 1 || scope.row.status == 2"
              type="text"
              @click="handleView(scope.row, 0)"
              >处理</el-button
            >
            <!-- <el-button
              size="mini"
              type="text"
              v-if="scope.row.status == 2 || scope.row.status == 4"
              @click="handleView(scope.row, 1)"
              >申请取消</el-button
            > -->
            <el-button
              size="mini"
              type="text"
              v-if="scope.row.status == 3 || scope.row.status == 4 || scope.row.status == 5 || scope.row.status == 6 || scope.row.status == 7 || scope.row.processingStatus == '已处理'"
              @click="handleView(scope.row, 2)"
              >查看详情</el-button
            >
            <!-- <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.row)"
              v-if="scope.row.status == 3 || scope.row.status == 5"
              >删除</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-show="total > 0"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-size="queryParams.pageSize"
        :current-page="queryParams.pageNum"
      >
      </el-pagination>
    </el-card>
    <!-- 确认任务 弹窗 -->
    <confirmDialog
      @changShow="changShow"
      :type="type"
      :expertId="expertId"
      :reviewTaskId="reviewTaskId"
      :confirmDialogShow.sync="confirmDialogShow"
    />
    <confirmDetailsDialog
      @changShow="changShow"
      :expertId="expertId"
      :reviewTaskId="reviewTaskId"
      :showDialog.sync="showDialog"
    />
  </div>
</template>
<script>
import { getExpertList, getExtractDelete } from "@/api/manage/manage";
import confirmDialog from "./components/confirmDialog";
import confirmDetailsDialog from "./components/confirmDetailsDialog";
import StatusBar, { mapToDict } from '@/views/components/statusBar';
function getIconClass(isStateName) {
  switch(isStateName) {
    case '待处理':
      return 'icon-state2';
    case '已处理':
      return 'icon-blue';
    case '已结束':
      return 'icon-state4'
    default:
      return 'icon-default';
  }
}
export default {
  name: "Expert",
  components: {
    confirmDialog,
    confirmDetailsDialog,
    StatusBar
  },
  filters: {
    getIconClass,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 专家表格数据
      reviewTasktList: [],
      // 总条数
      total: 1,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 日期范围
      dateRange: [],
      //任务状态
      statusOptions: [],
      //任务节点
      nodeOptions: [],
      confirmDialogShow: false, //处理弹窗
      showDialog: false, //查看弹窗
      reviewTaskId: "", //项目id
      expertId: "", //专家id
      type: "", //点击操作按钮状态
      processingStatusMap: mapToDict([
        ['all', '全部'],
        ['0', '待处理'],
        ['1', '已处理'],
        ['2', '已结束']
      ]),
      processingStatusQuery: {},
    };
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getlist();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      };
      this.dateRange = [];
      this.getlist();
    },
    /** 查看按钮操作 */
    //  0 处理  1 申请取消 2 查看详情/查看
    handleView(row, stateType) {
      this.reviewTaskId = row.reviewTaskId;
      this.expertId = row.expertId;
      if (row.status == 1) {
        this.confirmDialogShow = true;
      } else if (row.status == 3 || row.status == 7) {
        this.showDialog = true;
      } else if (row.status == 2 || row.status == 4) {
        if (stateType == 1) {
          this.type = "1";
          this.confirmDialogShow = true;
        } else {
          if (row.reviewType == 0) {
            this.$router.push({
              path: "/expert_pro/manage/expertEvaluation/details",
              query: {
                reviewTaskId: this.reviewTaskId,
                expertId: this.expertId,
              },
            });
          } else {
            this.$router.push({
              path: "/expert_pro/manage/expertEvaluation/auunalDetails",
              query: {
                reviewTaskId: this.reviewTaskId,
                expertId: this.expertId,
              },
            });
          }
        }
      } else {
        if (row.reviewType == 0) {
          this.$router.push({
            path: "/expert_pro/manage/expertEvaluation/details",
            query: {
              reviewTaskId: this.reviewTaskId,
              expertId: this.expertId,
            },
          });
        } else {
          this.$router.push({
            path: "/expert_pro/manage/expertEvaluation/auunalDetails",
            query: {
              reviewTaskId: this.reviewTaskId,
              expertId: this.expertId,
            },
          });
        }
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let _this = this;
      // const roleIds = row.roleId;
      _this
        .$confirm("是否确认删除 ？", "删除", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          customClass: "del_box",
        })
        .then(() => {
          const data = {
            reviewTaskId: row.reviewTaskId,
            expertId: row.expertId,
          };
          getExtractDelete(data).then((res) => {
            if (res.code == 200)
              this.$message({
                type: "success",
                message: "删除成功!",
              });
            this.getlist();
            console.log(res);
          });
        })
        .catch(() => {});
    },
    //获取列表
    getlist(query) {
      getExpertList({
        ...this.queryParams,
        ...this.processingStatusQuery,
        ...query,
      }).then((res) => {
        if (res.code == 200) {
          this.reviewTasktList = res.rows;
          this.total = res.total;
        }
      });
    },
    //处理时间
    checkTime(val) {
      console.log(val);
      this.queryParams.starTime = val[0] + " 00:00:00";
      this.queryParams.endTime = val[1] + " 23:59:59";
    },
    //分页
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.queryParams.pageNum = 1;
      this.getlist();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      this.getlist();
    },
    //弹框显示
    changShow(data) {
      if (data == "false") {
        this.confirmDialogShow = false;
        this.showDialog = false;
        this.type = "";
        this.getlist();
      }
    },
    changeProcessingStatus(query) {
      this.processingStatusQuery = query;
      this.queryParams.pageNum = 1;
      console.log(this.queryParams)
      this.getlist(query);
    }
  },
  created() {
    this.getlist();
    this.getDicts("review_task_status").then((res) => {
      this.statusOptions = res.data;
      console.log(res);
    });
    this.getDicts("extract_node").then((res) => {
      this.nodeOptions = res.data;
      console.log(res);
    });
  },
};
</script>
<style scoped lang="scss">
.expert-title {
  font-size: 18px;
  font-family: PingFang SC, PingFang SC-Medium;
  font-weight: 500;
  margin-bottom: 24px;
  color: #000000;
}
.card-table {
  margin-top: 10px;
  .el-pagination {
    text-align: center;
    margin-top: 40px;
  }
  // 状态也是
  .icon-state, .icon-blue{
    display: inline-block;
    width: 16px;
    height: 16px;
    background: rgba(49, 113, 238, 0.1);
    border-radius: 16px;
    position: relative;
    top: 3.5px;
    span {
      display: inline-block;
      margin: 4px;
      width: 7px;
      height: 7px;
      background: #3171ee;
      border-radius: 16px;
    }
  }
  .icon-state2 {
    background: rgba(223, 130, 45, 0.1);
    span {
      background: rgba(223, 130, 45, 1);
    }
  }
  .icon-state3 {
    background: rgba(223, 32, 66, 0.1);
    span {
      background: rgba(223, 32, 66, 1);
    }
  }
  .icon-state4 {
    background: rgba(51, 168, 61, 0.1);
    span {
      background: rgba(51, 168, 61, 1);
    }
  }
  .icon-state5 {
    background: rgba(95, 104, 123, 0.1);
    span {
      background: rgba(95, 104, 123, 1);
    }
  }
}
</style>
<style lang="scss">
.expert {
  .card-form {
    .el-card__body {
      padding-bottom: 0;
    }
    label {
      font-weight: normal !important;
    }
    .el-form--inline .el-form-item {
      margin-right: 32px;
    }
  }
  .card-table {
    .el-card__body {
      padding: 20px;
    }
  }
  /* 删除弹出框样式 */
  .del_box {
    width: 345px;
    height: 175px;
    .el-message-box__headerbtn {
      background: url("../../assets/images/icon_dialog_close.png");
      background-size: 100%;
      width: 16px;
      height: 16px;
      .el-message-box__close {
        visibility: hidden;
      }
    }
    .el-message-box__content {
      padding: 26px 95px;
      font-size: 16px;
      .el-message-box__status.el-icon-warning {
        color: #ea4747;
      }
      .el-message-box__status + .el-message-box__message {
        padding-right: 0;
      }
    }
  }
}
</style>
